下列函数中,哪两个函数具有相同的增长速度:
下列哪个函数是的?
给定的三维数组A,则在不改变数组的前提下,查找最小元素的时间复杂度是:
程序P1和P2时间复杂度的递推公式:
P1: , ;
P2: , ;
则下列关于两程序时间复杂度的结论中最准确的是:
斐波那契数列的定义为:, , , =2, 3, …。用递归函数计算的时间复杂度是:
斐波那契数列的定义为:, , , =2, 3, …。用递归函数计算的空间复杂度是:
For the following piece of code
for(i=0; i<n; i++)
for(j=i; j>0; j/=2)
printf(“%d\n”, j);
the time complexity is:
在数据结构中,从逻辑上可以把数据结构分成( )。
算法的时间复杂度取决于( )。
以下数据结构中,( )是非线性数据结构。
下列各种数据结构中属于线性结构的有()
以下说法正确的是( )。
下面程序段的时间复杂度是()。
x=90;
y=100;
while(y>0)
if(x>100)
{ x=x-10; y--; }
else x++;
下面代码段的时间复杂度是()。
for ( i=0; i<n; i++ )
for ( j=0; j<m; j++ )
a[i][j]=0;
下面代码段的时间复杂度是()。
i=1;
while( i<=n )
i=i*3;
下面代码段的时间复杂度是()。
x=n; //n>1
y=0;
while( x≥(y+1)*(y+1) )
y++;
下列代码
if ( A > B ) {
for ( i=0; i<N; i++ )
for ( j=N*N; j>i; j-- )
A += B;
}
else {
for ( i=0; i<N*2; i++ )
for ( j=N*2; j>i; j-- )
A += B;
}
的时间复杂度是:
Which one of the following is the lowest upper bound of for the following recursion ?
Given the following four algorithms with their runtimes for problem size 100 and their time complexities:
| Algorithm | Runtime | Time Complexity |
|---|---|---|
| A | 100 | |
| B | 30 | |
| C | 30 | |
| D | 10 |
Which algorithm is the fastest for problem size 200?
Given the following four algorithms with their runtimes for problem size 100 and their time complexities:
| Algorithm | Runtime | Time Complexity |
|---|---|---|
| A | 100 | |
| B | 50 | |
| C | 25 | |
| D | 10 |
Which algorithm is the fastest for problem size 200?
Given the following four algorithms with their runtimes for problem size 100 and their time complexities:
| Algorithm | Runtime | Time Complexity |
|---|---|---|
| A | 100 | |
| B | 50 | |
| C | 20 | |
| D | 15 |
Which algorithm is the fastest for problem size 200?
下面的程序段违反了算法的()原则。
void sam()
{ int n=2;
while (n%2==0) n+=2;
printf(“%d”,n);
}
下列程序的时间复杂度为()。
i = 0; s = 0;
while(s < n)
{
i++;
s = s + i;
}
下列程序段的时间复杂度为()。
x = n; /*n > 1*/
y = 0;
while(x >= (y + 1) * (y + 1))
y = y + 1;
求整数n(n>=0)的阶乘的算法如下,其时间复杂度为( )。
long fact(long n)
{
if (n<=1) return 1;
return n*fact(n-1);
}
下列复杂度表示法中,( )表示算法复杂度渐近的紧的界,即一种算法的复杂度与某个函数的阶相等。
下面算法所执行的加法次数( )。
输入:,其中,为正整数
输出:
k←0
while n>=1 do
for j←1 to n do
k=k+1
n←n/2
return k
已知求平方根函数的计算在时间内完成,下面算法的时间复杂度是( )。
Algorithm PrimalityTest
Input:
Output:true/false
s←sqrt(n)
for j←2 to s do
if (n mod j==0) then
return false
return true
T(n)表示当输入规模为n时的算法效率,以下算法中效率最优的是( )。
算法效率的比较
假设为解决某问题而设计的若干算法的时间复杂度分别为:
A)
B)
C)
D)
E)
F)
G)
H)
I)
J)
这些算法按效率由高到低的顺序是
注:请填大写字母。
算法的量度
(1) 算法所需执行时间的量度称为
(2) 算法所需存储空间的量度称为
渐近分析表示法
以时间复杂度为例,
以时间复杂度为例,
A) 大表示法
B) 大表示法
C)
D)
下面程序段的时间复杂度是
s =0;
for( i =0; i<n; i++)
for(j=0;j<n;j++)
s +=B[i][j];
sum = s ;
请写出下面程序段的时间复杂度为O(
void fun(int n)
{
int i=1;
while(i<n)
i*=3
}
测量算法的运行时间
下面的程序测量某个函数 F 的运行时间。
请在空白处填写适当内容,完成该程序。
#include <stdio.h>
#include < 5分 >
int F(int x);
int main()
{
int x, y;
clock_t t1, t2;
double t;
scanf("%d", &x);
t1 = 5分 ;
y = F(x);
t2 = 5分 ;
t = 6分 ;
printf("%d\n", y);
printf("It took %.2f second(s).\n", t);
return 0;
}
int F(int x)
{
...(略)...
}
25
3712
It took 0.18 second(s)
注:图中数据仅为样例,实际结果可能不同。